{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3e6dab07",
   "metadata": {},
   "source": [
    "# 本周知识点\n",
    "> 1. 回顾变量的概念\n",
    "> 2. 条件判断\n",
    "> 3. for循环和range方法\n",
    "> 4. random模块（伪随机数模块）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ec84bdc3",
   "metadata": {},
   "source": [
    "## 1、回顾变量的概念"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "0c937017",
   "metadata": {},
   "outputs": [],
   "source": [
    "网新_01_ID = \"21000001\"\n",
    "\n",
    "网新_02_ID = \"21000002\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "07dc840f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'21000001'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网新_01_ID"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "39624eb4",
   "metadata": {},
   "outputs": [],
   "source": [
    "网新_cjh_age = \"18\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "5cfd0145",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'18'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网新_cjh_age "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "052220ae",
   "metadata": {},
   "source": [
    "## 二、条件判断\n",
    ">if else"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "52db0506",
   "metadata": {},
   "outputs": [],
   "source": [
    "# wkday = 0，1，2，3，4，5，6   分别指周一到周日\n",
    "import time \n",
    "\n",
    "wday  = time.localtime().tm_wday"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "05f687f9",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_hour = time.localtime().tm_hour"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "f3efd9e8",
   "metadata": {},
   "outputs": [],
   "source": [
    "time_min = time.localtime().tm_min"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "f0457c90",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "今天有Python课\n"
     ]
    }
   ],
   "source": [
    "if wday != 1: # 判断是否是周二\n",
    "    print(\"今天有Python课\")\n",
    "elif time_hour == 12 and time_min > 50:\n",
    "    print(\"正在上Python课,刚上课\")\n",
    "elif time_hour == 13:\n",
    "    print(\"正在上Python课，大概第二节了\")\n",
    "elif time_hour == 14:\n",
    "    print(\"正在上Python课，妈呀，还在上，才2点\")\n",
    "elif time_hour == 15:\n",
    "    print(\"正在上Python课，坚持一下，快下课了！\")\n",
    "elif time_hour == 16 and time_min<50:\n",
    "    print(\"正在上Python课，最后一节课了，块下课啦\")\n",
    "else:\n",
    "    print(\"今天有Python课，上课时间是下午12.50-16.50\")\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "200d3dc8",
   "metadata": {},
   "source": [
    "## 三、for循环 内置函数range()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "a9068d91",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "for item in [1,2,3]:\n",
    "    print(item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "460fa169",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2100001\n",
      "2100002\n",
      "2100003\n"
     ]
    }
   ],
   "source": [
    "for item in [1,2,3]:\n",
    "    print(item+2100000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "80ce69ea",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "https://www.nfu.edu.cn/ztb/index.htm0.htm\n",
      "https://www.nfu.edu.cn/ztb/index.htm1.htm\n",
      "https://www.nfu.edu.cn/ztb/index.htm2.htm\n",
      "https://www.nfu.edu.cn/ztb/index.htm3.htm\n",
      "https://www.nfu.edu.cn/ztb/index.htm4.htm\n",
      "https://www.nfu.edu.cn/ztb/index.htm5.htm\n",
      "https://www.nfu.edu.cn/ztb/index.htm6.htm\n",
      "https://www.nfu.edu.cn/ztb/index.htm7.htm\n",
      "https://www.nfu.edu.cn/ztb/index.htm8.htm\n",
      "https://www.nfu.edu.cn/ztb/index.htm9.htm\n",
      "https://www.nfu.edu.cn/ztb/index.htm10.htm\n",
      "https://www.nfu.edu.cn/ztb/index.htm11.htm\n",
      "https://www.nfu.edu.cn/ztb/index.htm12.htm\n",
      "https://www.nfu.edu.cn/ztb/index.htm13.htm\n",
      "https://www.nfu.edu.cn/ztb/index.htm14.htm\n"
     ]
    }
   ],
   "source": [
    "#for循环遍历的案例：\n",
    "#中大南方-招投标- https://www.nfu.edu.cn/ztb/index.htm\n",
    "#学校要闻 = “xxyw”\n",
    " \n",
    "中大南方_招投标 = \"https://www.nfu.edu.cn/ztb/index.htm\"\n",
    "for page in range(15):\n",
    "    print(\"https://www.nfu.edu.cn/ztb/index.htm\" + str(page) + \".htm\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "0cb5e1b3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "#  range()自动生成想要的数值，可以控制for循环的次数，一个值，就是从0开始几个数\n",
    "for lunch in range(5):\n",
    "    print(lunch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "86047bb3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4\n",
      "5\n",
      "6\n",
      "7\n"
     ]
    }
   ],
   "source": [
    "# range()自动生成想要的数值，可以控制for循环的次数，两个值，从小数（2）开始，大数-小数的个数（5-2）\n",
    "for lunch in range(4,8):\n",
    "    print(lunch)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "8354a785",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "3\n",
      "6\n",
      "9\n",
      "12\n"
     ]
    }
   ],
   "source": [
    "# 三个值，第三个值决定step步长\n",
    "for lunch in range(0,13,3):\n",
    "    print(lunch)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4f3232c4",
   "metadata": {},
   "source": [
    "## 四、Random模块\n",
    ">1. random.random():生成随机数,0-1之间随机数（小数）\n",
    ">2. random.randint():生成随机数（整数）\n",
    ">3. 随机选择一个值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "54de17a0",
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "177737ac",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.31623366553095544"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# random.random方法: 取（0，1）\n",
    "random.random()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "38332540",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "53"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# random.randint(a,b),随机生成 a-b 之间的一个数值\n",
    "random.randint(1,99)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "39c21e09",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "1\n",
      "1\n",
      "4\n",
      "1\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "#randint小实践：大话骰\n",
    "for i in range(6):\n",
    "    print(random.randint(1,6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "91bde11c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'安东尼'"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.choice([\"詹姆斯\",\"韦德\",\"安东尼\",\"保罗\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "549afb2c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "72\n",
      "19\n",
      "49\n",
      "68\n",
      "48\n",
      "32\n"
     ]
    }
   ],
   "source": [
    "#通过随机值，大概判断彩票的中奖概率\n",
    "[12,35,48,10,87,93]\n",
    "for i in range(6):\n",
    "    print(random.randint(1,99))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "13859874",
   "metadata": {},
   "source": [
    "## 课本P35实践"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "581c9c9d",
   "metadata": {},
   "outputs": [],
   "source": [
    "#help (random)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "d382ade9",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "a1f1a07a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello world\n"
     ]
    }
   ],
   "source": [
    "time.sleep(5)\n",
    "print(\"hello world\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "7b582a9a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "24\n",
      "现在的时间/秒为偶数哈哈\n",
      "29\n",
      "现在的时间/秒为奇数哈哈\n",
      "31\n",
      "现在的时间/秒为奇数哈哈\n",
      "34\n",
      "现在的时间/秒为偶数哈哈\n",
      "37\n",
      "现在的时间/秒为奇数哈哈\n",
      "40\n",
      "现在的时间/秒为偶数哈哈\n",
      "45\n",
      "现在的时间/秒为奇数哈哈\n"
     ]
    }
   ],
   "source": [
    "import datetime\n",
    "import time\n",
    "import random\n",
    "\n",
    "odds = [  1, 3,  5,  7,  9, 11,13,15,17,19,\n",
    "             21,23,25,27,29,31,33,35,37,39,\n",
    "             41,43,45,47,49,51,53,55,57,59]\n",
    "for i in range(7):\n",
    "    right_this_minute = datetime.datetime.today().second\n",
    "    if right_this_minute in odds:\n",
    "        print(right_this_minute)\n",
    "        print(\"现在的时间/秒为奇数哈哈\")\n",
    "    else:\n",
    "        print(right_this_minute)\n",
    "        print(\"现在的时间/秒为偶数哈哈\")\n",
    "    time.sleep(random.randint(2,5))\n",
    "    \n",
    "# 爬虫，爬数据，每隔5秒抓一次数据\n",
    "# 反爬虫，"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "723233a2",
   "metadata": {},
   "source": [
    "## 课本P43实践"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "6e126fb5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 bottles 在啤酒墙上\n",
      "10 bottles 啤酒\n",
      "拿一瓶\n",
      "传递它\n",
      "9 bottles 还在啤酒墙上\n",
      "\n",
      "9 bottles 在啤酒墙上\n",
      "9 bottles 啤酒\n",
      "拿一瓶\n",
      "传递它\n",
      "8 bottles 还在啤酒墙上\n",
      "\n",
      "8 bottles 在啤酒墙上\n",
      "8 bottles 啤酒\n",
      "拿一瓶\n",
      "传递它\n",
      "7 bottles 还在啤酒墙上\n",
      "\n",
      "7 bottles 在啤酒墙上\n",
      "7 bottles 啤酒\n",
      "拿一瓶\n",
      "传递它\n",
      "6 bottles 还在啤酒墙上\n",
      "\n",
      "6 bottles 在啤酒墙上\n",
      "6 bottles 啤酒\n",
      "拿一瓶\n",
      "传递它\n",
      "5 bottles 还在啤酒墙上\n",
      "\n",
      "5 bottles 在啤酒墙上\n",
      "5 bottles 啤酒\n",
      "拿一瓶\n",
      "传递它\n",
      "4 bottles 还在啤酒墙上\n",
      "\n",
      "4 bottles 在啤酒墙上\n",
      "4 bottles 啤酒\n",
      "拿一瓶\n",
      "传递它\n",
      "3 bottles 还在啤酒墙上\n",
      "\n",
      "3 bottles 在啤酒墙上\n",
      "3 bottles 啤酒\n",
      "拿一瓶\n",
      "传递它\n",
      "2 bottles 还在啤酒墙上\n",
      "\n",
      "2 bottles 在啤酒墙上\n",
      "2 bottles 啤酒\n",
      "拿一瓶\n",
      "传递它\n",
      "1 bottle 还在啤酒墙上\n",
      "\n",
      "1 bottle 在啤酒墙上\n",
      "1 bottle 啤酒\n",
      "拿一瓶\n",
      "传递它\n",
      "没有更多的啤酒在啤酒墙上了，这瓶不给你，要展示的\n",
      "\n"
     ]
    }
   ],
   "source": [
    "word = \"bottles\"\n",
    "\n",
    "for beer_num in range(10,0,-1):\n",
    "    print(beer_num, word, \"在啤酒墙上\")\n",
    "    print(beer_num, word, \"啤酒\")\n",
    "    print(\"拿一瓶\")\n",
    "    print(\"传递它\")\n",
    "    if beer_num == 1:\n",
    "        print(\"没有更多的啤酒在啤酒墙上了，这瓶不给你，要展示的\")\n",
    "    else:\n",
    "        new_num = beer_num - 1\n",
    "        if new_num == 1:\n",
    "            word = \"bottle\"\n",
    "        print(new_num, word, \"还在啤酒墙上\")\n",
    "    print()   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c004be5e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
